"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("categories", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER,
      },
      name: {
        type: Sequelize.STRING(50),
        allowNull: false,
        comment: "分类名称",
      },
      parent_id: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        comment: "父分类ID，0表示顶级分类",
      },
      level: {
        type: Sequelize.TINYINT,
        allowNull: false,
        defaultValue: 1,
        comment: "分类层级",
      },
      sort_order: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "排序",
      },
      icon: {
        type: Sequelize.STRING(255),
        comment: "分类图标",
      },
      image: {
        type: Sequelize.STRING(255),
        comment: "分类图片",
      },
      is_show: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: "是否显示",
      },
      created_at: {
        allowNull: false,
        type: Sequelize.DATE,
      },
      updated_at: {
        allowNull: false,
        type: Sequelize.DATE,
      },
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable("categories");
  },
};
